package e.odbo.data.sample.security;

import java.util.ArrayList;
import java.util.List;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.*;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import e.odbo.data.dao.table.TableDefinition;
import e.odbo.data.dao.table.Field;
import e.odbo.data.format.Formats;
import e.odbo.data.dao.BaseDAO;

public class CustomFilterBeanDAO extends BaseDAO<CustomFilterBean> {

    public CustomFilterBeanDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                "APP_CUSTOM_FILTER",
                new Field[]{
                        new Field("ID", Datas.STRING, Formats.STRING),
                        new Field("USERID", Datas.STRING, Formats.STRING),
                        new Field("OBJECTTABLENAME", Datas.STRING, Formats.STRING),
                        new Field("OBJECTTABLENAMEDESC", Datas.STRING, Formats.STRING),
                        new Field("VALUE1", Datas.STRING, Formats.STRING)
                },
                new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, CustomFilterBean obj)
            throws BasicException {
        dp.setString(1, obj.getId());
        dp.setString(2, obj.getUserId());
        dp.setString(3, obj.getObjTableName());
        dp.setString(4, obj.getObjTableNameDesc());
        dp.setString(5, obj.getValue());
    }

    @Override
    public Class getSuportClass() {
        return CustomFilterBean.class;
    }

    @Override
    public CustomFilterBean readValues(DataRead dr, CustomFilterBean obj)
            throws BasicException {
        if (obj == null)
            obj = new CustomFilterBean();
        obj.setId(dr.getString(1));
        obj.setUserId(dr.getString(2));
        obj.setObjTableName(dr.getString(3));
        obj.setObjTableNameDesc(dr.getString(4));
        obj.setValue(dr.getString(5));
        return obj;
    }


    public List<CustomFilterBean> listCustomFilterBeanByUserAndTableName(final String userId, final String tableName) throws BasicException {
       /* return new PreparedSentence(s
                , getTableBuilderWarp().getListSQL() + " WHERE USERID = ? AND OBJECTTABLENAME=?"
                , SerializerWriteParams.INSTANCE
                , this).list(new DataParams() {
            public void writeValues() throws BasicException {
                setString(1, userId);
                setString(2, tableName);
            }
        });*/
       //@todo
        return new ArrayList<>();
    }

}
